﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Components;
using UI.Lib;

namespace UI.SellOrder
{
    public partial class Ord9a00Medit : UI.ParentForm.BaseMedit
    {
        public Ord9a00Medit(string modulecode, string action, string text, string key)
            : base(modulecode, action)
        {
            InitializeComponent();

            this.Text = text;
            this.Key = key;

            //回写的方法
            this.SaveCallFuntion = "Ord9a00Manager$SaveData"; //保存的方法
            IsAfterSaveCloseWin = false;
            this.allowDtlEmpty = false; //可能用户一次想把全部的记录删除

            this.Size = base.MaxWindow;
        }

        protected override bool BeforeDtlPopUp(string name, ref string where, ref string[] others)
        {
            if ("productcode" == name)
            {
                where = string.Format("status ='1' {0}", Context.GetAppKeyWhere("a.muser", true));
            }

            return true;
        }

        public override bool BeforePopWin(string name, ref string where, ref string[] others)
        {
            if ("sellercode" == name)
            {
                where = string.Format(" status ='1' {0} ", Context.GetAppKeyWhere("usercode", true));
            }
            else if ("shopcode" == name)//门店
            {
                string sellerid = Validation.ToString(this.tbSummary.GetValue("sellid"));
                if (string.IsNullOrEmpty(sellerid))
                {
                    MessageBox.Show("请先选择销售商！", "提示");
                    this.tbSummary.Focus("sellercode");
                    return false;
                }

                where = string.Format("slistid = '{0}' {1} ", sellerid, Context.GetAppKeyWhere("muser", true));
            }
            return true;
        }

        public override void AfterPopWin(string name, System.Collections.Hashtable data, bool ischange)
        {
            if (ischange)
            {
                if ("sellercode" == name)
                {
                    this.tbSummary.SetValue("shopid", "");
                    this.tbSummary.SetValue("shopcode", "");
                    this.tbSummary.SetValue("shopname", "");
                }
            }
        }

        protected override void AfterDtlValueChanged(string name, object value)
        {
            if ("price" == name || "qty" == name) //价格或者数量改变时，自动计算总金额
            {
                double price = Validation.ToDouble(this.dgvDtl.GetValue("price"));
                double qty = Validation.ToDouble(this.dgvDtl.GetValue("qty"));

                this.dgvDtl.SetValue("amt", Validation.ToDouble(price * qty, 3));
            }
        }
    }
}
